@extends('admin.layouts.wap_simple')
@section('title', '使用营业执照注册小程序')

@section('content')
<div class="main-back" style="padding:0 15px; overflow-y: auto;">
    <div class="m-mt-2">
        @if(empty($temMinis))
        <input type="hidden" name="id" id="id" value="0">
        <div class="m-form-item">
            <label><b>*</b>上传营业执照:</label>
            <div>
                <a href="javascript:;" class="m-file" style="float:left;margin-left: 0px;">
                    <font>上传</font>
                    <input type="file" name="upload_qualification_img" id="upload_qualification_img" onchange="beianUpload('qualification_img',1024,true,{},'all')">
                </a>
                <img src="" class="m-file-image" id="qualification_img_show" style="max-width: 300px;">
                <input type="hidden" name="qualification_img" id="qualification_img" value="">
            </div>
        </div>
        <div class="m-form-item m-col-12 m-xs-12">
            <label><b>*</b>法人微信:</label>
            <div class="m-col-12">
                <input type="text" class="m-input" id="legal_persona_wechat" placeholder="请输入法人微信号" maxlength="50" value="">
            </div>
        </div>
        <div class="m-form-item m-col-12 m-xs-12 up_show" style="display: none;">
            <label><b>*</b>企业名称:</label>
            <div class="m-col-12">
                <input type="text" class="m-input" id="name" placeholder="请输入企业名称" maxlength="30" value="">
            </div>
        </div>
        <div class="m-form-item m-col-12 m-xs-12 up_show" style="display: none;">
            <label><b>*</b>企业代码类型:</label>
            <select class="m-select" id="code_type">
                <option value="1" selected>统一社会信用代码</option>
                <option value="2">组织机构代码</option>
                <option value="3">营业执照注册号</option>
            </select>
        </div>
        <div class="m-form-item m-col-12 m-xs-12 up_show" style="display: none;">
            <label><b>*</b>统一社会信用代码:</label>
            <div class="m-col-12">
                <input type="text" class="m-input" id="code" placeholder="请输入营业执照统一社会信用代码" maxlength="18" value="">
            </div>
        </div>
        <div class="m-form-item m-col-12 m-xs-12 up_show" style="display: none;">
            <label><b>*</b>法人姓名:</label>
            <div class="m-col-12">
                <input type="text" class="m-input" id="legal_persona_name" placeholder="请输入法人姓名" maxlength="10" value="">
            </div>
        </div>
        <div class="m-form-item">
            <div class="m-btn m-btn-primary m-btn-block m-mt-1" onclick="fastRegisterMini(1);">保存模板并注册小程序</div>
            <div class="m-btn m-btn-primary m-btn-block m-mt-1" onclick="fastRegisterMini(2);">立即注册小程序</div>
        </div>
        @else
        <div class="m-form-item m-gap-4">
            <div class="m-col-12 m-xs-12">
            @csrf
                <label><b>*</b>企业信息模板:<font>前往管理 <a href="/admin/template/mini">小程序注册企业模板</a>。</font></label>
                <select class="m-select" name="id" id="id">
                    @forelse($temMinis as $key=>$temMini)
                    <option value="{{ $temMini->id }}" @if($key==0)selected @endif>{{ $temMini->enterprise_name }}</option>
                    @empty
                    <option value="">请选择注册的企业</option>
                    @endforelse
                </select>
            </div>
        </div>
        <div class="m-form-item">
            <div class="m-btn m-btn-primary m-btn-block m-mt-1" onclick="fastRegisterMini(3);">立即注册小程序</div>
        </div>
        @endif
        <div class="m-info-item">
            <label>特别提醒</label>
        </div>
        <div class="m-info-item">
            <div class="text">
                <ul>
                    <li>1、注册成功企业法人微信会收到一条推送，按照推送完成认证即可；</li>
                    <li>2、每个企业法人最多绑定5个小程序，上限后需要把管理转出去才能重新注册! </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<script src="https://file.wailian1.cn/admin/assets/admin/js/libs/image-conversion/conversion.js"></script>
<script type="text/javascript" src="/assets/admin/js/dev/image.upload.875451.js?v={{ time() }}"></script>
<script>
    function jsUploadCallBack(id,imageurl,imageName,updata,other) {
        //上传识别营业执照
        $(".up_show").show();
    }
    function fastRegisterMini(type){
        var id = $("#id").val();
        if(type==3){
            if (id == "" || id == 0) {
                mviewToastr("error","请选择小程序注册企业模板!"); 
                return;
            }
            $.ajax({
                "url": "/admin/miniapps/miniapp_register_corp_submit",
                "type": "GET",
                "data": {"id":id},
                success: function(res){
                    if (res.status == "success") {
                        mviewToastr("success",res.msg); 
                        setTimeout(function() {
                            window.location.href = "/admin/miniapps/miniapp_lists";
                        },2000);
                    } else {
                        mviewToastr("error",res.msg,5);
                    }
                },
                error: function(err){
                    mviewToastr("error","网络异常,请刷新网页后重试!");
                }
            });
        }else{
            var legal_persona_wechat = $("#legal_persona_wechat").val();
            var name = $("#name").val();
            var code_type = $("#code_type").val();
            var code = $("#code").val();
            var legal_persona_name = $("#legal_persona_name").val();
            var qualification_img = $("#qualification_img").val();
            if (legal_persona_wechat == "" || legal_persona_wechat.length < 4) {
                mviewToastr("error","请输入正确的法人微信号!");
                return;
            }
            if (name == "" || name.length < 2) {
                mviewToastr("error","请输入正确的企业名称!");
                return;
            }
            if (code == "" || code.length < 15) {
                mviewToastr("error","请输入正确的统一社会信用代码!");
                return;
            }
            if (legal_persona_name == "" || legal_persona_name.length < 2) {
                mviewToastr("error","请输入正确的法人姓名!"); 
                return;
            }
            $.ajax({
                "url": "/admin/miniapps/miniapp_register_corp_submit",
                "type": "GET",
                "data": {
                    id:id,
                    type:type,
                    legal_persona_wechat:legal_persona_wechat,
                    name:name,
                    code_type:code_type,
                    code:code,
                    legal_persona_name:legal_persona_name,
                    qualification_img:qualification_img
                },
                success: function(res){
                    if (res.status == "success") {
                        mviewToastr("success",res.msg); 
                        setTimeout(function() {
                            window.location.href = "/admin/miniapps/miniapp_lists";
                        },2000);
                    } else {
                        mviewToastr("error",res.msg,5);
                    }
                },
                error: function(err){
                    mviewToastr("error","网络异常,请刷新网页后重试!");
                }
            });
        }
    }
</script>

@endsection
